<?php
	session_start();
	require "../modules/conn.php";
	$uphone=$_REQUEST["uphone"];
	$upassword=$_REQUEST["upassword"];
	$sql1="select * from t_user where uphone=$uphone";
	$result1=mysqli_query($conn,$sql1);

	if($row=mysqli_fetch_row($result1)){
		if($row[2]==$upassword){
			$_SESSION["uid"]=$row[0];
			$_SESSION["uname"]=$row[1];
			// 检查用户是否勾选了免登录
			if (isset($_REQUEST["stayin"])) {
				// 存入cookie
				setcookie("uname", $row[1], time()+7*24*60*60);
				setcookie("uid", $row[0], time()+7*24*60*60);
			} else {
				// 存入cookie，只在浏览器打开访问期间有效（因为page.php是先检查cookie登录再检查会话中有无uid值）
				setcookie("uname", $row[1]);
				setcookie("uid", $row[0]);
			}
			header("Location:../watchlist.html");
		}else{
			echo "<script>
			alert('your password is wrong');
			location='../login_regist.html';
			</script>";
		}
	}else{
		echo "<script>
			alert('you dose not regist,please to regist');
			location='../login_regist.html';
			</script>";
	}
?>